
#include "storageao_test.h"
#include "logservice/logger.h"
#include "app_platform/cntl_info.h"
#include "app_platform/help_macros.h"
#include "app_platform/res_factory.h"
#include "c2cplatform/component/session_sync3/online_session_check.h"
#include "c2cent/library/log/CWTimeElf2.h"

#include <stdio.h>
#include <string>
#include "erp/storage/po/stockpo_storage.h"	
#include "erp/storage/po/stockfilterpo_storage.h"	
#include <set>	
#include <map>	
#include <vector>	
#include "../src/storageao.h"

using namespace erp::storage::ao;

// 把这个TestSuite注册到名字为"alltest"的TestSuite中, 如果没有定义会自动定义
// 也可以CPPUNIT_TEST_SUITE_REGISTRATION( MathTest );注册到全局的一个未命名的TestSuite中.
// 此处必须， 不要改动
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(CStorageAoTest, "alltest");

CCntlInfo g_oDummyCntlInfo;

// 初始化函数，在函数内添加需要初始化的全局变量
void CStorageAoTest::setUp()
{
	//添加测试的需全局使用的初始化
	ONLINE_SEESION_R->Enable(false);
	LOGGER->setDebug(true);
    C2C_WWLOG->QuickInitForAPP("storageao_unittest");
}

//清理函数，free等操作
void CStorageAoTest::tearDown()
{
	//把之前new的变量free等清理操作
}

//cppunit提供的一些测试验证宏，可以在函数中使用
//
//CPPUNIT_ASSERT(condition)                     // 确信condition为真
//CPPUNIT_ASSERT_MESSAGE(message, condition)	// 当condition为假时失败, 并打印message
//CPPUNIT_FAIL(message)                         // 当前测试失败, 并打印message
//CPPUNIT_ASSERT_EQUAL(expected, actual)        // 确信两者相等
//CPPUNIT_ASSERT_EQUAL_MESSAGE(message, expected, actual)    // 失败的同时打印message
//CPPUNIT_ASSERT_DOUBLES_EQUAL(expected, actual, delta)      // 当expected和actual之间差大于delta时失败
//

//测试函数
	void CStorageAoTest::testAddStock()
	{
	    CStorageAo oSvc(DEPLOY_MOCK);
					std::string machineKey = "";		
					std::string source = "";		
					uint32_t sceneId = 0;
					uint32_t option = 0;
					erp::storage::po::CStockPo StockInfo;
					std::string inReserve = "";		
					std::string errmsg = "";		
					std::string outReserve = "";		
		
		uint32_t dwResult = oSvc.AddStock(
			g_oDummyCntlInfo,
			machineKey,
			source,
			sceneId,
			option,
			StockInfo,
			inReserve,
			errmsg,
			outReserve
	        );
	
	    CPPUNIT_ASSERT(dwResult == 0);
	}
	void CStorageAoTest::testDeleteStock()
	{
	    CStorageAo oSvc(DEPLOY_MOCK);
					std::string machineKey = "";		
					std::string source = "";		
					uint32_t sceneId = 0;
					uint32_t option = 0;
					std::set<uint64_t > FStockSysNo;
					std::string inReserve = "";		
					std::string errmsg = "";		
					std::map<uint64_t,uint32_t > errorCode;
					std::map<uint64_t,std::string > errorMsg;
					std::string outReserve = "";		
		
		uint32_t dwResult = oSvc.DeleteStock(
			g_oDummyCntlInfo,
			machineKey,
			source,
			sceneId,
			option,
			FStockSysNo,
			inReserve,
			errmsg,
			errorCode,
			errorMsg,
			outReserve
	        );
	
	    CPPUNIT_ASSERT(dwResult == 0);
	}
	void CStorageAoTest::testGetStockByIds()
	{
	    CStorageAo oSvc(DEPLOY_MOCK);
					std::string machineKey = "";		
					std::string source = "";		
					uint32_t sceneId = 0;
					std::set<uint64_t > IDList;
					std::string inReserve = "";		
					std::string errmsg = "";		
					std::vector<erp::storage::po::CStockPo > StockList;
					std::string outReserve = "";		
		
		uint32_t dwResult = oSvc.GetStockByIds(
			g_oDummyCntlInfo,
			machineKey,
			source,
			sceneId,
			IDList,
			inReserve,
			errmsg,
			StockList,
			outReserve
	        );
	
	    CPPUNIT_ASSERT(dwResult == 0);
	}
	void CStorageAoTest::testGetStockList()
	{
	    CStorageAo oSvc(DEPLOY_MOCK);
					std::string machineKey = "";		
					std::string source = "";		
					uint32_t sceneId = 0;
					erp::storage::po::CStockFilterPo StockFilter;
					std::string inReserve = "";		
					std::string errmsg = "";		
					uint32_t total = 0;
					std::vector<erp::storage::po::CStockPo > StockList;
					std::string outReserve = "";		
		
		uint32_t dwResult = oSvc.GetStockList(
			g_oDummyCntlInfo,
			machineKey,
			source,
			sceneId,
			StockFilter,
			inReserve,
			errmsg,
			total,
			StockList,
			outReserve
	        );
	
	    CPPUNIT_ASSERT(dwResult == 0);
	}
	void CStorageAoTest::testUpdateStock()
	{
	    CStorageAo oSvc(DEPLOY_MOCK);
					std::string machineKey = "";		
					std::string source = "";		
					uint32_t sceneId = 0;
					uint32_t option = 0;
					erp::storage::po::CStockPo StockInfo;
					std::string inReserve = "";		
					std::string errmsg = "";		
					std::string outReserve = "";		
		
		uint32_t dwResult = oSvc.UpdateStock(
			g_oDummyCntlInfo,
			machineKey,
			source,
			sceneId,
			option,
			StockInfo,
			inReserve,
			errmsg,
			outReserve
	        );
	
	    CPPUNIT_ASSERT(dwResult == 0);
	}
